var num = [2, 7, 11, 15]

var target = 10;


var searchInsert = function (nums, target) {
    var flag = -1;
    try {
        nums.forEach((item, index) => {
            if (item >= target) {
                flag = index
                throw new Error("end")
            }else {
                flag = index+1
            }
        });
    } catch (e) {
       if(e.message == 'end') {
       }
    }
    return flag;
}

console.log(searchInsert(num, target));
